﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Common;
using DemoManageSys.Areas.Filters;
using IBLL;
using Microsoft.AspNetCore.Mvc;
using Models;
using Models.DTO;

namespace DemoManageSys.Areas.Admin.Controllers
{
    [Area("Admin")]
    [MyFilter]
    public class SupplierInfoController : Controller
    {
        private ISupplierInfoBLL _categoryBLL;

        public SupplierInfoController(
            ISupplierInfoBLL categoryBLL
            )
        {
            _categoryBLL = categoryBLL;
        }

        #region 显示视图
        public IActionResult ListView()
        {
            return View();
        }

        public IActionResult CreateView()
        {
            return View();
        }

        public IActionResult EditView()
        {
            return View();
        }
        #endregion

        #region 获取供应商表的方法 (GetSupplierInfoes)
        /// <summary>
        /// 获取供应商表的方法
        /// </summary>
        /// <param name="limit"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetSupplierInfo(int limit, int page, string categoryName)
        {
            int count;
            List<GetSupplierInfoDTO> getSupplierInfoDTOs = _categoryBLL.GetSupplierInfo(limit, page, categoryName, out count);
            ReturnResule resule = new ReturnResule()
            {
                Code = 0,
                Msg = "获取成功",
                Data = getSupplierInfoDTOs,
                Count = count
            };
            return Json(resule);
        }
        #endregion

        #region 添加的方法 (CreateSupplierInfo)
        /// <summary>
        /// 添加的方法
        /// </summary>
        /// <param name="cate"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult CreateSupplierInfo([FromForm] SupplierInfo cate)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();
            string msg;//定义返回消息
            resule.IsSuccess = _categoryBLL.CreateSupplierInfo(cate, out msg);//调用方法传值
            if (resule.IsSuccess)
            {
                resule.Code = 200;
            }
            resule.Msg = msg;

            return Json(resule);
        }
        #endregion

        #region 删除的方法 (DeleteSupplierInfo)
        /// <summary>
        /// 删除的方法
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult DeleteSupplierInfo(string id)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();
            if (string.IsNullOrWhiteSpace(id))
            {
                resule.Msg = "删除供应商的id不能为空";
                return Json(resule);
            }

            resule.IsSuccess = _categoryBLL.DeleteSupplierInfo(id);//调用方法传值

            if (resule.IsSuccess)
            {
                resule.Code = 200;
            }
            resule.Msg = resule.IsSuccess ? "删除供应商成功" : "删除供应商失败";

            return Json(resule);
        }
        #endregion

        #region 批量软删除供应商的方法 (DeleteListSupplierInfoo)
        /// <summary>
        /// 批量软删除供应商的方法
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult DeleteListSupplierInfoo(List<string> ids)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();
            if (ids.Count == 0)
            {
                resule.Msg = "你没有返回任何耗材";
                return Json(resule);
            }
            resule.IsSuccess = _categoryBLL.DeleteListSupplierInfo(ids);//调用方法传值
            if (resule.IsSuccess)
            {
                resule.Code = 200;
            }
            resule.Msg = resule.IsSuccess ? "删除耗材成功" : "删除耗材失败";

            return Json(resule);
        }
        #endregion

        #region 修改的方法 (UpdateSupplierInfo)
        /// <summary>
        /// 修改的方法
        /// </summary>
        /// <param name="cate"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdateSupplierInfo([FromForm] SupplierInfo cate)
        {
            //实例化对象
            ReturnResule resule = new ReturnResule();

            string msg;//定义返回消息
            resule.IsSuccess = _categoryBLL.UpdateSupplierInfo(cate, out msg);//调用方法传值

            resule.Msg = msg;
            if (resule.IsSuccess)
            {
                resule.Code = 200;
            }

            return Json(resule);
        }
        #endregion
    }
}